package business.global.pk.ddz.cardtype.type;

import business.ddz.c2s.cclass.DDZ_define;
import business.global.pk.alg.params.BaseOpCard;
import business.global.pk.alg.params.BasePKParameter;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;

public class TypeWeight {
    //最大权重
    public static final int maxWeight = 1000000;

    public static int getWeight(BaseOpCard parameter, int reminding) {
        int weight = 0;
        if (parameter.opCardType == DDZ_define.DDZ_CARD_TYPE.DDZ_CARD_TYPE_ZHADAN.value()) {
            weight += 700;
        } else if (parameter.opCardType == DDZ_define.DDZ_CARD_TYPE.DDZ_CARD_TYPE_FEIJI2.value()) {
            weight += 600;
        } else if (parameter.opCardType == DDZ_define.DDZ_CARD_TYPE.DDZ_CARD_TYPE_FEIJI1.value()) {
            weight += 700;
        } else if (parameter.opCardType == DDZ_define.DDZ_CARD_TYPE.DDZ_CARD_TYPE_FEIJI0.value()) {
            weight += 700;
        } else if (parameter.opCardType == DDZ_define.DDZ_CARD_TYPE.DDZ_CARD_TYPE_4DAI4.value()) {
            weight += 400;
        } else if (parameter.opCardType == DDZ_define.DDZ_CARD_TYPE.DDZ_CARD_TYPE_4DAI2.value()) {
            weight += 450;
        } else if (parameter.opCardType == DDZ_define.DDZ_CARD_TYPE.DDZ_CARD_TYPE_4DAI21.value()) {
            weight += 400;
        } else if (parameter.opCardType == DDZ_define.DDZ_CARD_TYPE.DDZ_CARD_TYPE_4DAI1.value()) {
            weight += 450;
        } else if (parameter.opCardType == DDZ_define.DDZ_CARD_TYPE.DDZ_CARD_TYPE_LIANDUI.value()) {
            weight += 500;
        } else if (parameter.opCardType == DDZ_define.DDZ_CARD_TYPE.DDZ_CARD_TYPE_SHUNZI.value()) {
            weight += 450;
        } else if (parameter.opCardType == DDZ_define.DDZ_CARD_TYPE.DDZ_CARD_TYPE_3BUDAI.value()) {
            weight += 200;
        } else if (parameter.opCardType == DDZ_define.DDZ_CARD_TYPE.DDZ_CARD_TYPE_3DAI2.value()) {
            weight += 200;
        } else if (parameter.opCardType == DDZ_define.DDZ_CARD_TYPE.DDZ_CARD_TYPE_3DAI1.value()) {
            weight += 180;
        } else if (parameter.opCardType == DDZ_define.DDZ_CARD_TYPE.DDZ_CARD_TYPE_DUIZI.value()) {
            weight += 700;
        } else if (parameter.opCardType == DDZ_define.DDZ_CARD_TYPE.DDZ_CARD_TYPE_SINGLECARD.value()) {
            weight += 500;
        }
        weight += parameter.cardList.size() * 5;//张数权重分
        if (parameter.cardList.size() == reminding) {
            weight += maxWeight;
            if (parameter.opCardType == DDZ_define.DDZ_CARD_TYPE.DDZ_CARD_TYPE_ZHADAN.value()) {
                weight += maxWeight;
            }
        }
        parameter.weight = weight;
        return weight;
    }

    public static BaseOpCard getRandomCard(int totalWeight, List<BaseOpCard> opCardList, List<Integer> chanceList) {
        Random random = new Random();
        int randomNumber = random.nextInt(totalWeight);
        int min = 0;
        int max = 0;
        for (int i = 0; i < chanceList.size(); i++) {
            Integer next = chanceList.get(i);
            max = max + next;
            if (randomNumber >= min && randomNumber <= max) {
                return opCardList.get(i);
            }
            min = max;
        }
        return opCardList.size() > 0 ? opCardList.get(0) : new BaseOpCard();
    }
}
